
$(function (){
    $.post($("#hidden_info").attr("rel")+"/Admin/findAll",{},function (data){
        var table = $("#table");
        for(var i=0;i<data.length;i++){
            table.append("<tr><td>"+data[i].id
                +"</td><td>"+data[i].name
                +"</td><td>"+data[i].phone
                +"</td><td>"+data[i].sex
                +"</td><td>"+data[i].password
                +"</td><td><a href='admin_update.jsp?id="
                +data[i].id
                +"'"
                +" class='update_btn btn btn-primary'>修改</a>&nbsp;&nbsp;<button class='btn btn-danger delete_btn'>删除</button></td></tr>");
        }
        // $(".update_btn").click(function() {
        //     var row = $(this).closest("tr");
        //     //获取数据
        //     alert(row.find("td:eq(1)").text());
        // });
        $(".delete_btn").click(function() {
            var row = $(this).closest("tr");
            var val = row.find("td:eq(0)").text();
           $.post($("#hidden_info").attr("rel")+"/Admin/delete",{id:val},function (data){
                if(data.flag){
                    location.href = "admin_con.jsp";
                }else{
                    alert("删除失败！");
                }
                return false;
           });
           return false;
        });
    });

    $("#i_btn").click(function (){

        $.post($("#hidden_info").attr("rel")+"/Admin/register",$("#insert").serialize(),function (data){
            if(data.flag){
                location.href = "admin_con.jsp";
            }else{
                alert("新增失败！");
            }
            return false;
        });
        return false;
    });

});

function register_id_verify(){
    var element = $("#InputID");
    var str = element.val();
    var reg = /^\d+$/;
    var is = reg.exec(str);
    var span = $("#InputID_text");
    var path = $("#hidden_info").attr("rel");
    mark = false;
    $.post(path+"/Admin/valid", {id:str},function (data){
        if(is){
            if(data.flag){
                mark = true;
            }else{
                alert("工号已存在");
                mark = false;
            }

        }else{
            alert("工号不能为空或非数字");
            mark = false;

        }

    });

    return mark;
}